<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><title>API调用日志</title>
<link rel="stylesheet" href="/layui/css/layui.css"><script src="/static/js/jquery.min.js"></script><script src="/layui/layui.js"></script>
<style>body{background:#f5f5f5;padding:20px;}</style></head>
<body>
<div class="layui-card"><div class="layui-card-header">API调用日志 <button class="layui-btn layui-btn-sm layui-btn-normal" style="float:right;" onclick="exportLog()">导出Excel</button></div>
<div class="layui-card-body"><div class="layui-form layui-form-pane" style="margin-bottom:15px;"><div class="layui-inline"><input type="text" id="appId" placeholder="AppID" class="layui-input" value="<?= htmlspecialchars($appId) ?>" style="width:160px;"></div><div class="layui-inline"><select id="apiName"><option value="">全部接口</option><option value="idcard_2" <?= $apiName=='idcard_2'?'selected':'' ?>>身份证二要素</option><option value="face" <?= $apiName=='face'?'selected':'' ?>>人脸识别</option><option value="phone_3" <?= $apiName=='phone_3'?'selected':'' ?>>运营商三要素</option></select></div><div class="layui-inline"><select id="statusFilter"><option value="-1" <?= $status==-1?'selected':'' ?>>全部状态</option><option value="1" <?= $status===1?'selected':'' ?>>成功</option><option value="0" <?= $status===0?'selected':'' ?>>失败</option></select></div><div class="layui-inline"><input type="text" id="startTime" placeholder="开始日期" class="layui-input" value="<?= htmlspecialchars($startTime) ?>" style="width:130px;"></div><div class="layui-inline"><input type="text" id="endTime" placeholder="结束日期" class="layui-input" value="<?= htmlspecialchars($endTime) ?>" style="width:130px;"></div><button class="layui-btn layui-btn-primary layui-btn-sm" onclick="search()">搜索</button></div>
<table class="layui-table" lay-size="sm"><thead><tr><th>ID</th><th>用户ID</th><th>AppID</th><th>接口</th><th>状态</th><th>耗时(秒)</th><th>IP</th><th>时间</th><th>请求参数</th></tr></thead>
<tbody><?php foreach($list as $item): ?><tr><td><?= $item['id'] ?></td><td><?= $item['user_id'] ?></td><td><?= $item['app_id'] ?></td><td><?= $item['api_title'] ?: $item['api_name'] ?></td><td><?= $item['status']?'<span style="color:green">成功</span>':'<span style="color:red">失败</span>' ?></td><td><?= $item['cost_time'] ?></td><td><?= $item['ip'] ?></td><td><?= $item['create_time'] ?></td><td style="max-width:200px;word-break:break-all;"><?= htmlspecialchars($item['request_params'] ?? '') ?></td></tr><?php endforeach; ?><?php if(empty($list)):?><tr><td colspan="9" style="text-align:center;color:#999;">暂无数据</td></tr><?php endif;?></tbody></table><div id="page"></div></div></div>
<script>
var total=<?=$total?>,page=<?=$page?>,pageSize=<?=$pageSize?>;
layui.use(['laypage','laydate'],function(){var p=layui.laypage,d=layui.laydate;d.render({elem:'#startTime',type:'date'});d.render({elem:'#endTime',type:'date'});if(total>pageSize){p.render({elem:'page',count:total,limit:pageSize,curr:page,jump:function(o,f){if(!f) location.href='/admin/log/apiLog?page='+o.curr+'&app_id=<?=urlencode($appId)?>&api_name=<?=$apiName?>&status=<?=$status?>&start_time=<?=urlencode($startTime)?>&end_time=<?=urlencode($endTime)?>';}});}});
function search(){location.href='/admin/log/apiLog?app_id='+encodeURIComponent($('#appId').val())+'&api_name='+$('#apiName').val()+'&status='+$('#statusFilter').val()+'&start_time='+encodeURIComponent($('#startTime').val())+'&end_time='+encodeURIComponent($('#endTime').val());}
function exportLog(){location.href='/admin/log/exportLog?app_id=<?=urlencode($appId)?>&api_name=<?=$apiName?>&start_time=<?=urlencode($startTime)?>&end_time=<?=urlencode($endTime)?>';}
</script></body></html>